﻿// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "pch.h"
#include "DataReciver.h"
#include "InstanceMgr.h"

HHOOK mouseHook = 0;

LRESULT CALLBACK mymouse(int nCode, WPARAM wParam, LPARAM lParam)
{
	if (wParam == WM_MOUSEMOVE)//只处理WM_MOUSEMOVE消息
	{
		MOUSEHOOKSTRUCT * mhookstruct;//鼠标HOOK结构体
		mhookstruct = (MOUSEHOOKSTRUCT*)lParam;
		POINT pt = mhookstruct->pt;
		if (pt.x < 0 || pt.y < 0)
		{
			printf("mouse:(%d,%d)", pt.x, pt.y);
		}
	}
	return CallNextHookEx(mouseHook, nCode, wParam, lParam);
}

void RegistMouseHook() {
	//DWORD threadid= GetCurrentThreadId();
	mouseHook = SetWindowsHookEx(WH_MOUSE_LL, mymouse, 0, 0);
}

void MouseLoop() {
	//thread thread(RegistMouseHook);
	RegistMouseHook();
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{

    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
		//MouseLoop();
        sInstanceMgr.GetReciver().RegistHook();
        break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
        break;
    case DLL_PROCESS_DETACH:
        sInstanceMgr.GetReciver().RemoveHook();
        break;
    }
    return TRUE;
}

